<template>

  <el-row type="flex" justify="space-between" align="middle" style="height: 40px ;width:100%">
    <el-col>
      <strong v-if="judge">{{ treeData.name }}</strong>
      <span v-else>{{ treeData.name }}</span>
    </el-col>
    <el-col :span="4">
      <el-row type="flex" justify="end">
        <!-- 两个内容 -->
        <el-col>{{ treeData.principal }}</el-col>
        <el-col>
          <!-- 下拉菜单 element -->
          <el-dropdown>
            <span>
              操作<i class="el-icon-arrow-down" />
            </span>
            <!-- 下拉菜单 -->
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="addFn">添加子部门</el-dropdown-item>
              <el-dropdown-item v-if="!judge" @click.native="changeDepartmentFn">查看部门</el-dropdown-item>
              <el-dropdown-item v-if="!judge" @click.native="delCompanyFn(treeData.id)">删除子部门</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>

</template>

<script>
import { delCompanyList } from '@/api/company'
export default {
  props: {
    treeData: {
      type: Object,
      required: true
    },
    judge: {
      default: false,
      type: Boolean
    }
  },
  methods: {
    // 点击查看/修改按钮触发的函数
    changeDepartmentFn() {
      // 展示弹出框
      // 将部门信息传递给父组件
      // this.$emit('changeShow', this.treeData)
      // 告诉父组件此时需要获取部门数据了
      this.$emit('isTimeGet', this.treeData)
    },
    delCompanyFn(id) {
      delCompanyList(id)
    },
    addFn() {
      // 将部门的信息传给父组件
      this.$emit('changeShow', this.treeData)
    }
  }
}
</script>

<style>

</style>
